﻿#include "ConstantDescEx.h"

#include <DescStore/ConstantConstantDesc.h>

ConstantDescEx::ConstantDescEx()
{
	if (EN_OBJ_MODE_INIT == NFShmMgr::Instance()->GetCreateMode()) {
		CreateInit();
	}
	else {
		ResumeInit();
	}
}

ConstantDescEx::~ConstantDescEx()
{
}

int ConstantDescEx::CreateInit()
{
	return 0;
}

int ConstantDescEx::ResumeInit()
{
	return 0;
}

int ConstantDescEx::Load()
{
	return 0;
}

int ConstantDescEx::CheckWhenAllDataLoaded()
{
    for (int i = 0; i < ConstantConstantDesc::Instance()->GetResNum(); ++i)
    {
        auto pDesc = ConstantConstantDesc::Instance()->GetDescByIndex(i);
        CHECK_EXPR(pDesc, -1, "ConstantConstantDesc::Instance()->GetDescByIndex({}) failed", i);

        CHECK_EXPR(pDesc->id == pDesc->name, -1, "constant id and name are not same: {} {}", pDesc->id, pDesc->name);
    }
	return 0;
}

float ConstantDescEx::GetValue(proto_ff::enConstType eType)
{
	auto pDesc = ConstantConstantDesc::Instance()->GetDesc(eType);
	CHECK_EXPR(pDesc, 0, "ConstantConstantDesc::Instance()->GetDesc({}:{})", eType, proto_ff::enConstType_Name(eType));
	return pDesc->value;
}
